import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * Created by Administrator on 2018/3/23 0023.
 */
public class BCrypt {
    /**
     *
     * @param str
     * @return
     */
    public static String encode_base64(String str) {
        try {
            BASE64Encoder encoder = new BASE64Encoder();
            byte[] b = str.getBytes("UTF-8");
            String encodeText = encoder.encode(b);
            return encodeText;
        }catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String decode_base64(String str) {
        try {
            BASE64Decoder decoder = new BASE64Decoder();
            byte[] bytes = decoder.decodeBuffer(str);
            String result = new String(bytes, "UTF-8");
            return result;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
